package cn.cloud.project.consumer.controller;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;

/**
 * @author: cql
 * @date: 2024/11/3
 * @description:
 */
@RestController
@RequestMapping("/consumer")
public class ConsumerController {

    @Value("${server.port}")
    private String port;

    @Resource
    private RestTemplate restTemplate;


    @GetMapping("/test")
    public String testConsumer() {
        return "我是服务消费者：" + port;
    }


    /**
     * 测试注册中心 与 负载均衡组件的整合能力
     */
    @GetMapping("/test/loadBalanced")
    public String testLoadBalanced() {
        ResponseEntity<String> response = restTemplate.getForEntity("http://demo-provider/provider/test/loadBalanced", String.class);
        return "测试注册中心 与 负载均衡组件的整合能力: " + response.getBody();
    }

}
